package day11demo;

public class Demo2 {
    public static void main(String[] args) {
        String a = "abcde";
        String b = "eabcd";
        int count = 0;
        String c = a;
        for (int i = 0; i < a.length(); i++) {
            c = rotate(c);
            System.out.println(c);
            count++;
            if (flag(c, b)) {
                System.out.println("匹配成功");
                break;
            } else {
                System.out.println("匹配失败");
            }
        }
    }

    public static boolean flag(String s, String st) {
        if (s.equals(st)) {
            return true;
        } else {
            return false;
        }
    }

    // 字符串截取
    public static String rotate(String str) {
        String s = str.substring(1);
        s = s + str.charAt(0);
        return s;
    }
//利用字符数组，转录  字符串
    public static String changString(String str){
        char[] arr = str.toCharArray();
        char first = arr[0];
        for (int i = 1; i < arr.length; i++) {
            arr[i-1] = arr[i];
        }
        arr[arr.length-1] = first;
        String result = new String(arr);
        return result;

    }

    /*public static String changeString(String str) {
        char start = str.charAt(0);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (i == str.length() - 1) {
                sb.append(start);
            } else {
                sb.append(str.charAt(i + 1));
            }
        }
        return sb.toString();
    }*/
}
